package com.easy.controller;

import com.easy.bean.Bed;
import com.easy.bean.Doctor;
import com.easy.common.CommonResult;
import com.easy.dao.IDoctorDao;
import com.easy.service.IDoctorService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
@RestController
public class DoctorController {
    @Autowired
    IDoctorDao dao;
    @Autowired
    IDoctorService dtS;

    @GetMapping("doctorname")
    public CommonResult getDoctorName() {
        List<String > da = dtS.getDoctorName();
        System.out.println( da); // 输出床位号码
        return CommonResult.success(da);
    }
    @GetMapping("doctorbydep_id")
    public CommonResult  getDoctorByDep_id(Doctor doctor){
        List<Doctor> list=dtS.getDoctorByDep_id(doctor);
        return CommonResult.success(list);
    }

    @GetMapping("doctor")
    public CommonResult getDoctor(Doctor doctor, Page page){
        List<Doctor> list=dtS.getDoctor(doctor,page);
        int count=dtS.getCount(doctor);
        HashMap map=new HashMap();
        map.put("list",list);
        map.put("count",count);
        return CommonResult.success(map);

    }
    @PostMapping("doctor")
    public CommonResult addDoctorJSON(@RequestBody Doctor doctor){
        dtS.addDoctor(doctor);
        doctor=dtS.getDoctorById(doctor.getId());
        return CommonResult.success(doctor);
    }

    @DeleteMapping("doctor/{id}")
    public CommonResult delDoctor(@PathVariable int id){
        int count=dao.delDoctor(id);
        if(count>0){
            return CommonResult.success();
        }else {
            return CommonResult.fail();
        }
    }
    @PutMapping("doctor")
    public CommonResult editDoctorJSON(@RequestBody Doctor doctor ){
        dtS.editDoctor(doctor);
        doctor=dtS.getDoctorById(doctor.getId());
        return CommonResult.success(doctor);
    }
}
